class ListNode {
    constructor(val) {
        this.val = val
        this.next = null
    }

    static initWithList(l) {
        const size = l.length
        if (size === 0) {
            return null
        }

        let head = new ListNode(l[0])
        let pre = head
        for (let i = 1; i<size; i++) {
            pre.next = new ListNode(l[i])
            pre = pre.next
        }
        return head
    }

    description() {
        let des = `${this.val}`
        let cur = this.next
        while(cur != null) {
            des += ` -> ${cur.val}`
            cur = cur.next
        }

        return des
    }

}

export {ListNode}